package controllers

import "github.com/gin-gonic/gin"

type OrderController struct{}

func (o OrderController) GetList(c *gin.Context) {
	ReturnSuccess(c, 2, "操作成功order list", "", 1)
}

func (o OrderController) GetList2(c *gin.Context) {
	cid := c.PostForm("cid")
	name := c.DefaultPostForm("name", "wangwu")

	ReturnSuccess(c, 0, cid, name, 1)
}

func (o OrderController) Add(c *gin.Context) {
	param := make(map[string]interface{})
	err := c.BindJSON(&param)
	if err == nil {
		ReturnSuccess(c, 0, cid, name, 1)
	}

}

func (o OrderController) GetInfo(c *gin.Context) {
	cid := c.Query("cid")
	name := c.DefaultPostForm("name", "wangwu")

	ReturnSuccess(c, 0, cid, name, 1)
}

// 结构体接收数据
type Search struct {
	Name string `json:"name"`
	Cid  int    `json:"cid"`
}

// 教程  https://www.bilibili.com/video/BV1Jy4y1F7RG/?p=7&spm_id_from=pageDriver&vd_source=59a043573a31ee96bd5739d020fab746
func (o OrderController) Add2(c *gin.Context) {
	search := &Search{}
	err := c.BindJSON(&search) // 这里为啥要&
	if err == nil {
		ReturnSuccess(c, 0, search.Name, search.Cid, 1)
		return
	}
	ReturnError(c, 4001, gin.H{"err": err})
}
